package com.flower.controller.admin;

import com.flower.annotation.Log;
import com.flower.domain.vo.admin.analysis.*;
import com.flower.service.ShopAnalysisService;
import com.flower.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端店铺数据分析
 */
@Slf4j
@RestController
@RequestMapping("/admin/analysis/shop")
public class ShopAnalysisController {

    @Autowired
    private ShopAnalysisService shopAnalysisService;

    /**
     * 获取店铺销售趋势数据
     */
    @GetMapping("/sales-trend")
    public AjaxResult getShopSalesTrend(
            @RequestParam Integer shopId,
            @RequestParam(defaultValue = "month") String timeRange) {
        if (shopId == null) {
            return AjaxResult.error("店铺ID不能为空");
        }
        ShopSalesTrendVO trendData = shopAnalysisService.getShopSalesTrend(shopId, timeRange);
        return AjaxResult.success(trendData);
    }

    /**
     * 获取店铺订单状态分布
     */
    @GetMapping("/order-status")
    public AjaxResult getShopOrderStatusDistribution(
            @RequestParam Integer shopId,
            @RequestParam(defaultValue = "month") String timeRange) {
        if (shopId == null) {
            return AjaxResult.error("店铺ID不能为空");
        }
        ShopOrderStatusVO statusData = shopAnalysisService.getShopOrderStatusDistribution(shopId, timeRange);
        return AjaxResult.success(statusData.getItems());
    }

    /**
     * 获取店铺热销商品
     */
    @GetMapping("/top-products")
    public AjaxResult getShopTopProducts(
            @RequestParam Integer shopId,
            @RequestParam(defaultValue = "month") String timeRange,
            @RequestParam(defaultValue = "10") Integer limit) {
        if (shopId == null) {
            return AjaxResult.error("店铺ID不能为空");
        }
        ShopTopProductsVO topProducts = shopAnalysisService.getShopTopProducts(shopId, timeRange, limit);
        return AjaxResult.success(topProducts);
    }

    /**
     * 获取店铺商品类别分布
     */
    @GetMapping("/category-distribution")
    public AjaxResult getShopCategoryDistribution(
            @RequestParam Integer shopId,
            @RequestParam(defaultValue = "month") String timeRange) {
        if (shopId == null) {
            return AjaxResult.error("店铺ID不能为空");
        }
        ShopCategoryDistributionVO categoryData = shopAnalysisService.getShopCategoryDistribution(shopId, timeRange);
        return AjaxResult.success(categoryData);
    }
} 